<template>
<!-- <div style="padding: 10px">题目信息</div> -->
  <div>
    <el-descriptions
        :column="2"
        border
        size="small"
        class="mt-4"
    >
      <el-descriptions-item label="描述" :span="6">
        <el-input v-model="ruleForm.title" type="textarea"/>
      </el-descriptions-item>
      <el-descriptions-item label="类型" :span="6">
        <el-radio-group v-model="ruleForm.questionType">
          <el-radio :label=0>单选题</el-radio>
          <el-radio :label=1>多选题</el-radio>
        </el-radio-group>
      </el-descriptions-item>
      <el-descriptions-item label="备注" :span="6">
        <el-input v-model="ruleForm.remark"/>
      </el-descriptions-item>
    </el-descriptions>
  </div>

</template>

<script lang="ts" setup>
import {reactive, ref} from 'vue'
import type {FormInstance, FormRules} from 'element-plus'
import {ElMessage} from "element-plus";
import router from "@/router";
import {STATUS_LIST} from '@/util/common.util';
import {DepressQuestion} from '@/apis/model/depress/DepressQuestionModel';
import {insertDepressQuestion, updateDepressQuestion} from '@/apis/http/depress/DepressQuestionHttp';

interface Prop {
  ruleForm: DepressQuestion
}

// 传递过来的参数
const props = defineProps<Prop>();

const formSize = ref('default')
const ruleFormRef = ref<FormInstance>()

const rules = reactive<FormRules>({
  id: [
    {required: true, message: '请输入ID', trigger: 'blur'}
  ],
  title: [
    {required: true, message: '请输入题目', trigger: 'blur'}
  ],
  questionType: [
    {required: true, message: '请输入题目类型', trigger: 'blur'}
  ],
  statusFlag: [
    {required: true, message: '请输入状态 0-停用 1-启用 2-备用', trigger: 'blur'}
  ],
  delFlag: [
    {required: true, message: '请输入是否删除 0-否 1-是', trigger: 'blur'}
  ],
  createUser: [
    {required: true, message: '请输入创建人', trigger: 'blur'}
  ],
  createTime: [
    {required: true, message: '请输入创建时间', trigger: 'blur'}
  ],
  updateTime: [
    {required: true, message: '请输入修改时间', trigger: 'blur'}
  ],
  remark: [
    {required: true, message: '请输入备注', trigger: 'blur'}
  ],
})

const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      // 新增
      if (props.addDataType === 'add') {
        insertDepressQuestion(props.ruleForm).then(res => {
          const code = res.code;
          const message: string = res.message;
          const data = res.data;
          if (code == 200) {
            ElMessage({
              message: '创建成功！',
              type: 'success',
            })
            refushList.value = true
            closeEditDialog()
          } else {
            ElMessage.error('创建失败！')
          }
        })
      } else if (props.addDataType === 'edit') {
        updateDepressQuestion(props.ruleForm).then(res => {
          const code = res.code;
          const message: string = res.message;
          const data = res.data;
          if (code == 200) {
            ElMessage({
              message: '更新成功！',
              type: 'success',
            })
            refushList.value = true
            closeEditDialog()
          } else {
            ElMessage.error('更新失败！')
          }
        })
      }
    } else {
      ElMessage.error('请完善信息！')
    }
  })
}
</script>

<style scoped>
.dialog-footer button:first-child {
  margin-right: 10px;
}
</style>
